package com.dream.wuliu.utils;

import android.app.DatePickerDialog;
import android.content.Context;
import android.widget.DatePicker;
import android.widget.EditText;

public class MyDatePicker {
	
	private Context context;
	
	private MyDatePart date;
	
	private EditText etDate;
	
	public static void  createDialog(Context context,EditText etDate){
		 
		createDialog(context,etDate,MyDatePart.today());
	}
	
	public static void  createDialog(Context ct,EditText etDate,MyDatePart date){
		
		 MyDatePicker picker = new MyDatePicker();
		 picker.context = ct;
		 picker.date = date;
		 picker.etDate = etDate;
		 DatePickerDialog dialog = new DatePickerDialog(picker.context, picker.mDateSetListener, picker.date.getYear(), picker.date.getMonth(), picker.date.getDay());
		 dialog.show();
	}

	private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { 
		public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
			    	   date.setYear(year);
			    	   date.setMonth(monthOfYear);
			    	   date.setDay(dayOfMonth);
			    	   updateDate(date);
	    } 
	}; 
	
	public void updateDate(MyDatePart date){
		etDate.setText(date.toString());
	}
}
